package com.k.kpp.service;

import com.k.kpp.dao.UserMapper;
import com.k.kpp.model.UserReq;
import com.k.kpp.model.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author k
 */
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public List selectUser() {
        return userMapper.selectAll();
    }

    @Override
    public Long selectCount(UserReq req) {
        return userMapper.selectCount(req);
    }

    @Override
    public List selectListByPage(UserReq req) {
        return userMapper.selectListByPage(req);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertUserRollback() {
        User u = new User(7,"ljw7","ljw7@email.com");
        int r1 = userMapper.insertUser(u);
        System.out.println("r1:"+r1);
        User u2 = new User(7,"ljw7","ljw7@email.com");
        int r2 = userMapper.insertUser(u2);
        System.out.println("r2:"+r2);
        return r2;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertUser() {
        User u = new User(8,"ljw8","ljw8@email.com");
        int r = userMapper.insertUser(u);
        return r;
    }

    @Override
    public int deleteArr(Integer[] idArr) {
        return userMapper.deleteArr(idArr);
    }

    @Override
    public int deleteList(List<Integer> idList) {
        return userMapper.deleteList(idList);
    }

}
